<?php
class Default_Model_University extends Zend_Db_Table{
	protected $_name = 'university_info';
	protected $_primary = 'uid';
	
	public function listNameArea(){
		$db = Zend_Registry::get('connectDb');
		$select = $db->select()
					 ->from('areaschool AS a', array('a.areaid', 'name'));
		$result = $db->fetchAll($select);
	
		return $result;
	}
	
	public function uniList($areaID){
		$db = Zend_Registry::get('connectDb');
		$select = $db->select()
					 ->from('university_info AS u', array('uid', 'linkcollege', 'namecollege', 'typecollege'))
					 ->joinLeft('areaschool AS a', 'u.areaid = a.areaid', array('a.areaid', 'name'))
					 ->where('a.areaid = ' . $areaID);
		$result = $db->fetchAll($select);
	
		return $result;
	}
	
	public function infoUni(){
		$db = Zend_Registry::get('connectDb');
		//$db = Zend_Db::factory($adapter, $config);
	
		$tblNameArea = $this->listNameArea();
		$countNameArea = count($tblNameArea);
		$xHTML = '';
		for($i=0; $i<$countNameArea; $i++){
			$areaID = $tblNameArea[$i]['areaid'];
			$xHTML .= '<h3 class="title">State <strong  style="text-transform: uppercase;">' . $tblNameArea[$i]['name'] . '</strong></h3>';
			$xHTML .= '<table class="box">';
			$xHTML .= '<tr class="tableHeader">';
			$xHTML .= '<th>School ID</th>';
			$xHTML .= '<th>School Name</th>';
			$xHTML .= '<th>School Type</th>';
			$xHTML .= '</tr>';
			$infoUniversity = $this->uniList($areaID);
			$count = count($infoUniversity);
			$item = 1;
			for($j=0; $j<$count; $j++){
				if($item < 10){
					$stt = '<td>' . 0 . $item . '</td>';
				}else{
					$stt = '<td>' . $item . '</td>';
				}
				$xHTML .= '<tr>';
				$xHTML .= $stt;
				$xHTML .= '<td><a href="' . $infoUniversity[$j]['linkcollege'] . '" target="_blank">' . $infoUniversity[$j]['namecollege'] . '</a></td>';
				$xHTML .= '<td>' . $infoUniversity[$j]['typecollege'] . '</td>';
				$xHTML .= '</tr>';
				$item ++;
			}
			$xHTML .= '</table>';
		}
		return $xHTML;
	}
}